package com.zzuli.dcxt.service.impl;

import com.zzuli.dcxt.dao.PagingMapper;
import com.zzuli.dcxt.entiy.User;
import com.zzuli.dcxt.service.PagingService;
import com.zzuli.dcxt.utils.Paging;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PagingServiceImpl implements PagingService {
    @Autowired
    private PagingMapper pagingMapper;
    @Override
    public List<User> paging(Paging paging) {
     //总条数
    int total = pagingMapper.getTotal();
    //总页数
    int totalPage;
    if(total%paging.getPageSize()==0){
        totalPage=total/paging.getPageSize();
        paging.setTotalPage(totalPage);
    }else {
        totalPage=total/ paging.getPageSize()+1;
        paging.setTotalPage(totalPage);
    }
    if (paging.getPageIndex()>totalPage){
            paging.setPageIndex(totalPage);
        }
        System.out.println("service的最后一页的下一页"+paging.getPageIndex());
        int start=(paging.getPageIndex()-1)* paging.getPageSize();
        int length=paging.getPageSize();
        List<User> userList=pagingMapper.paging(start,length);
     return userList;
    }
}
